#ifndef _LED_H_
#define _LED_H_

#include "Global.h"
#include "SC_GPIO.h"

#define _COM_ANODE_   (0)     // 共阳

//#define P_LED_COM0  RB3
//#define P_LED_COM1  RB4
// #define P_LED1      RA0
// #define P_LED2      RA1
// #define P_LED3      RA2
// #define P_LED4      RA3
// #define P_LED5      RA4

#define P_LED1    DEF_PIN(B,6)
#define M_LED1    DEF_PIN_DIR(B, 6)
#define WPU_LED1  DEF_PIN_WPU(B, 6)

#define P_LED2    DEF_PIN(B,7)
#define M_LED2    DEF_PIN_DIR(B, 7)
#define WPU_LED2  DEF_PIN_WPU(B, 7)

#define P_LED3    DEF_PIN(A,7)
#define M_LED3    DEF_PIN_DIR(A, 7)
#define WPU_LED3  DEF_PIN_WPU(A, 7)

#define P_LED4    DEF_PIN(A,6)
#define M_LED4    DEF_PIN_DIR(A, 6)
#define WPU_LED4  DEF_PIN_WPU(A, 6)

#define P_LED5    DEF_PIN(A,5)
#define M_LED5    DEF_PIN_DIR(A, 5)
#define WPU_LED5  DEF_PIN_WPU(A, 5)

#define P_LED_COM0    DEF_PIN(B,3)
#define M_LED_COM0    DEF_PIN_DIR(B, 3)
#define WPU_LED_COM0  DEF_PIN_WPU(B, 3)

#define P_LED_COM1    DEF_PIN(B,4)
#define M_LED_COM1    DEF_PIN_DIR(B, 4)
#define WPU_LED_COM1  DEF_PIN_WPU(B, 4)

#define P_LED_COM2    DEF_PIN(B,5)
#define M_LED_COM2    DEF_PIN_DIR(B, 5)
#define WPU_LED_COM2  DEF_PIN_WPU(B, 5)

#define SET_IN(pin)      do{P_##pin = 1;  M_##pin = 1; WPU_##pin = 1;} while(0)
#define SET_OUT(pin,hl)  do{P_##pin = hl; M_##pin = 0; WPU_##pin = 0;} while(0)
#define GET_PIN(pin)    P_##pin
 
#define EN_LED1()       do{SET_OUT(LED1,LOW);}while(0)         //P_LED1 = LOW
#define DIS_LED1()      do{SET_IN(LED1);}while(0)   //P_LED1 = HIGH
#define EN_LED2()       do{SET_OUT(LED2,LOW);}while(0)        //P_LED2 = LOW
#define DIS_LED2()      do{SET_IN(LED2);}while(0)   //P_LED2 = HIGH
#define EN_LED3()       do{SET_OUT(LED3,LOW);}while(0)        //P_LED3 = LOW
#define DIS_LED3()      do{SET_IN(LED3);}while(0)   //P_LED3 = HIGH
#define EN_LED4()       do{SET_OUT(LED4,LOW);}while(0)         //P_LED4 = LOW
#define DIS_LED4()      do{SET_IN(LED4);}while(0)  //P_LED4 = HIGH
#define EN_LED5()       do{SET_OUT(LED5,LOW);}while(0)        //P_LED5 = LOW
#define DIS_LED5()      do{SET_IN(LED5);}while(0)   //P_LED5 = HIGH
// #define LED_ALL_OFF()   do{P_LED1=HIGH; P_LED2=HIGH; P_LED3=HIGH; P_LED4=HIGH; P_LED5=HIGH;}while(0)
#define LED_ALL_OFF()   do{P_LED_COM0=LOW; P_LED_COM1=LOW; P_LED_COM2=LOW; }while(0)

enum
{
    LED1 = 0x01,
    LED2 = 0x02,
    LED3 = 0x04,
    LED4 = 0x08,
    LED5 = 0x10,
};

enum
{
    TOP = 0x01,
    BOTTOM=0x02,
};


typedef struct 
{
    uint8 Buf;
    uint8 TopOrBottom;
    uint16 Cnt;
    uint16 TmOn;
    uint16 TmPeriod;
    uint8 Loop;
    void(*FuncCallBack)(void);
}Typedef_LED;


// extern volatile uint16 TimeLedOn;




#define ALL_ON      0xFF
#define ALL_OFF     0x00
// #define BLINK_SEND  LED5

// #define LED_PAIR        (LED1+LED2+LED3)
// #define LED_SEND        LED5
#define TIME_BASE_LED   8
// #define TM_LED_SHORT    (600/TIME_BASE_LED)
// #define TM_LED_DISP     (3000/TIME_BASE_LED)
// #define TM_LED_MODE     (1000/TIME_BASE_LED)
// #define TM_LED_LONG     (5000/TIME_BASE_LED)
// #define TM_LED_POWER_ON (1000/TIME_BASE_LED)
// #define TM_LED_PAIR     (15000ul/TIME_BASE_LED)

// extern uint8 RLedBuf;
// extern bit F_LED_SEND;
// extern const uint8 TAB_LED[];

void    initLED(void);
// void LED_Set(uint8 buf, uint16 tm_on, uint16 tm_period, uint8 loop);
void LED_Set(uint8 buf, uint8 TopOrBottom, uint16 tm_on, uint16 tm_period, uint8 loop,void(*FuncTimerCallBack)(void));
void    LED_Main(void);
uint8   LED_Check(void);

#endif
